<!-- 
说明：订单表表单
作者：292303959@qq.com
日期：2018-10-17 10:5:39
版本：1.0.0
-->
<template>

  <el-dialog :title="title"
             append-to-body
             visible
             lock-scroll
             :before-close="handleClose"
             width="800px">
    <div ref="printDialog">
      <el-form ref="form"
               :model="form"
               :label-width="ui.formLabelWidth"
               :element-loading-text="ui.loadingText"
               v-loading="ui.busying">
        <el-row type="flex">
          <el-col :span="24">
            <mk-form-item label="订单编号"
                          prop="orderid"
                          :mk-le-length="32">
              {{form.orderid}}
            </mk-form-item>
          </el-col>
          <el-col :span="24">
            <mk-form-item label="会员名称"
                          prop="mname"
                          :mk-le-length="32">
              {{form.mname}}
            </mk-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="24">
            <mk-form-item label="收件人"
                          prop="recipients"
                          :mk-le-length="32">
              {{form.recipients}}
            </mk-form-item>
          </el-col>
          <el-col :span="24">
            <mk-form-item label="手机"
                          prop="cellphone"
                          :mk-le-length="15">
              {{form.cellphone}}
            </mk-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="24">
            <mk-form-item label="收货地址"
                          prop="adress"
                          :mk-le-length="500">
              {{form.province}} {{form.city}} {{form.area}} {{form.adress}}
            </mk-form-item>
          </el-col>
        </el-row>
        <mk-card>
          <div slot="header"
               class="clearfix">
            <span>商品明细</span>
          </div>
          <mk-table mk-index
                    :data="form.orderDetail"
                    :mk-page="false"
                    height="auto"
                    ref="table">
            <el-table-column align="left"
                             prop="pdname"
                             label="商品名称"
                             width="250" />
            <el-table-column align="left"
                             prop="brname"
                             label="系列名称"
                             width="250" />
            <el-table-column align="left"
                             prop="psname"
                             label="规格"
                             width="130" />
            <el-table-column align="left"
                             prop="detailrnumber"
                             label="发货数量"
                             width="100">
              <template slot-scope="scope">
                {{scope.row.detailrnumber-(scope.row.aftersalenum | 0)}}
              </template>
            </el-table-column>
          </mk-table>
        </mk-card>
      </el-form>
    </div>
    <div slot="footer">
      <mk-button @click="handleClose">取消</mk-button>
      <mk-button @click="onSubmit"
                 :type="2">{{btnName}}</mk-button>
    </div>
  </el-dialog>
</template>

<script>
import { MkBase } from 'element-ui'
import formData from './form-data'
import cloneDeep from 'lodash.clonedeep'
export default {
  name: 't-order-form',
  mixins: [MkBase],
  props: {
    psid: String,
    isAdd: Boolean,
    title: String,
    btnName: String,
    row: Object
  },
  async mounted () {
    if (this.isAdd === false) {
      const form = cloneDeep(this.row)
      form.orderDetail = []
      this.form = form
    }
    this.ui.busying = false
    let viewDate = await this.$get('/tOrderDetail/list.json', {orderid: this.form.orderid})
    this.form.orderDetail = viewDate.list
  },
  data () {
    const form = formData()
    return {
      ui: {
        formLabelWidth: '100px',
        busying: true,
        loadingText: '正在加载'
      },
      form
    }
  },
  methods: {
    async valid () {
      if (!this.validate) {
        let fn = this.$refs.form.validate
        let nodejs = false
        this.validate = this.$promise({ fn, nodejs })
      }
      return await this.validate()
    },
    async onSubmit () {
      let printHtmls = this.$refs.printDialog.innerHTML
      window.sessionStorage.setItem('aa', printHtmls)
      window.open(window.location.origin + '/t-order/print')
    },
    handleClose () {
      this.$emit('close')
    }
  }
}
</script>
